import { get, post, del, put } from '../utils/request';
import { ApiResponse, ForumSection, ForumTopic, ForumReply, PageResult } from '../types';

/**
 * 获取论坛板块列表
 */
export function getForumSections() {
  return get<ApiResponse<ForumSection[]>>('/forum/sections');
}

/**
 * 获取板块主题列表
 */
export function getSectionTopics(sectionId: number, params?: {
  page?: number;
  size?: number;
}) {
  return get<ApiResponse<PageResult<ForumTopic>>>(`/forum/sections/${sectionId}/topics`, params);
}

/**
 * 获取主题详情
 */
export function getTopicDetail(topicId: number) {
  return get<ApiResponse<ForumTopic>>(`/forum/topics/${topicId}`);
}

/**
 * 获取主题回复列表
 */
export function getTopicReplies(topicId: number, params?: {
  page?: number;
  size?: number;
}) {
  return get<ApiResponse<PageResult<ForumReply>>>(`/forum/topics/${topicId}/replies`, params);
}

/**
 * 发表新主题
 */
export function createTopic(data: {
  sectionId: number;
  title: string;
  content: string;
}) {
  return post<ApiResponse<ForumTopic>>('/forum/topics', data);
}

/**
 * 回复主题
 */
export function replyTopic(topicId: number, data: {
  content: string;
}) {
  return post<ApiResponse<ForumReply>>(`/forum/topics/${topicId}/replies`, data);
}

/**
 * 删除主题
 */
export function deleteTopic(topicId: number) {
  return del<ApiResponse<null>>(`/forum/topics/${topicId}`);
}

/**
 * 删除回复
 */
export function deleteReply(replyId: number) {
  return del<ApiResponse<null>>(`/forum/replies/${replyId}`);
}

/**
 * 点赞回复
 */
export function likeReply(replyId: number) {
  return post<ApiResponse<null>>(`/forum/replies/${replyId}/like`);
}

/**
 * 点赞主题
 */
export function likeTopic(topicId: number) {
  return post<ApiResponse<null>>(`/forum/topics/${topicId}/like`);
}

/**
 * 置顶/取消置顶主题
 */
export function toggleTopicSticky(topicId: number) {
  return put<ApiResponse<null>>(`/forum/topics/${topicId}/sticky`);
}

/**
 * 锁定/解锁主题
 */
export function toggleTopicLock(topicId: number) {
  return put<ApiResponse<null>>(`/forum/topics/${topicId}/lock`);
}

/**
 * 增加主题查看次数
 */
export function increaseTopicViewCount(topicId: number) {
  return post<ApiResponse<string>>(`/forum/topics/${topicId}/view`);
} 